﻿' <summary>
' BeeWit IDE Entorno de desarrollo Visual para php.
' BeeWitPHP IDE es el único entorno de desarrollo para PHP 
' de tipo WYSIWYG (What You See Is What You Get). 
' ¡Ahora si!, aproveche la potencia del lenguaje PHP 
' y desarrolle más rápidamente gracias a la programación 
' intuitiva de BeeWit.
' Copyright © 2010 Dewins Murillo Garcia 
' EMAIL: dewinsmg@gmail.com
' EMAIL: dewins@beewitsoft.com
' Este Programa es Software Libre: usted puede redistribuirlo 
' y/o modificarlo bajo los términos de la Licencia Publica General 
' GNU como es publicada por la Fundacion de Software Libre; 
' en la 3ra versión de la licencia.
' Este programa es distribuido con la esperanza de que sea útil, 
' pero SIN GARANTÍA ALGUNA; sin siquiera la garantía implícita 
' de VALOR COMERCIAL o FORMADO PARA UN PROPÓSITO EN PARTICULAR. 
' Vea la Licencia Publica General GNU para mas detalles.
' Usted debe haber recibido una copia de la Licencia Publica General 
' GNU junto con este programa. Si no, vaya a http://www.beewitsoft.com
' o en http://code.google.com/p/ajax-beewit-php-ide/
' </summary>
' <remarks></remarks>

Imports System.IO

Public Class clsLocalFiles
    Implements ifzFilesManager

    Public Function Conect(ByVal Path As String, ByVal User As String, ByVal Password As String) As Boolean Implements ifzFilesManager.Conect

    End Function

    Public Function CopyDirectory(ByVal PathOld As String, ByVal PathNew As String, ByVal Notify As Boolean) As Boolean Implements ifzFilesManager.CopyDirectory

    End Function

    Public Function CopyFile(ByVal PathOld As String, ByVal PathNew As String, ByVal Notify As Boolean) As Boolean Implements ifzFilesManager.CopyFile
        Try
            System.IO.File.Copy(PathOld, PathNew, Notify)
        Catch ex As Exception
            If Notify Then
                MsgBox(ex.Message, MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Copy"))
            End If
        End Try
    End Function

    Public Function CreateDirectory(ByVal Path As String, ByVal Notify As Boolean) As Boolean Implements ifzFilesManager.CreateDirectory
        Try
            If Not IO.Directory.Exists(Path) Then
                IO.Directory.CreateDirectory(Path)
                Return True
            Else
                MsgBox(Object_Language.Lang_Text("Directory exists"), MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Creating New Directory"))
                Return False
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Creating New Directory"))
        End Try
    End Function

    Public Function CreateFile(ByVal Path As String, ByVal Notify As Boolean) As Boolean Implements ifzFilesManager.CreateFile
        Try
            If Not IO.File.Exists(Path) Then
                Dim sw As StreamWriter = IO.File.CreateText(Path)
                sw.Write("")
                sw.Flush()
                sw.Close()
                Return True
            Else
                If Notify Then
                    MsgBox(Object_Language.Lang_Text("File exists"), MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Creating new file"))
                Else
                    Return True
                End If
                Return False
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Creating new file"))
        End Try
    End Function

    Public Function DeleteDirectory(ByVal Path As String, ByVal Notify As Boolean) As Boolean Implements ifzFilesManager.DeleteDirectory
        Try
            If IO.Directory.Exists(Path) Then
                IO.Directory.Delete(Path)
                Return True
            Else
                MsgBox(Object_Language.Lang_Text("Directory don't exists"), MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Deleting"))
                Return False
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Deleting"))
        End Try
    End Function

    Public Function DeleteFile(ByVal Path As String, ByVal Notify As Boolean) As Boolean Implements ifzFilesManager.DeleteFile
        Try
            If IO.File.Exists(Path) Then
                IO.File.Delete(Path)
                Return True
            Else
                If Notify Then
                    MsgBox(Object_Language.Lang_Text("File don't exists"), MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Deleting"))
                End If
                Return False
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Deleting"))
        End Try
    End Function

    Public Function Disconect(ByVal Path As String, ByVal User As String, ByVal Password As String) As Boolean Implements ifzFilesManager.Disconect

    End Function

    Public Function GetContentFile(ByVal Path As String) As String Implements ifzFilesManager.GetContentFile
        Try
            If Path.IndexOf(".") < 0 Then
                Return ""
            Else
                Return IO.File.ReadAllText(Path)
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, Object_Language.Lang_Text("Getting content of file"))
            Return ""
        End Try
    End Function

    Public Function ListDirectories(ByVal Path As String) As ifzFilesManager.strFile() Implements ifzFilesManager.ListDirectories
        Try
            Dim DirNames() As String = Directory.GetDirectories(Path)
            Dim Directories(DirNames.Count - 1) As ifzFilesManager.strFile
            Dim iCount As Long = 0
            For Each DirName In DirNames
                Directories(iCount).Path = DirName
                Directories(iCount).Name = DirName.Substring(DirName.LastIndexOf("\") + 1)
                iCount += 1
            Next
            Return Directories
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return Nothing
    End Function

    Public Function ListFiles(ByVal Path As String) As ifzFilesManager.strFile() Implements ifzFilesManager.ListFiles
        Try
            Dim FileNames() As String = Directory.GetFiles(Path)
            Dim Files(FileNames.Count - 1) As ifzFilesManager.strFile
            Dim iCount As Long = 0
            For Each FileName In FileNames
                Files(iCount).Path = FileName
                Files(iCount).Name = FileName.Substring(FileName.LastIndexOf("\") + 1)
                iCount += 1
            Next
            Return Files
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return Nothing
    End Function

    Public Function MoveDirectory(ByVal PathOld As String, ByVal PathNew As String, ByVal Notify As Boolean) As Boolean Implements ifzFilesManager.MoveDirectory

    End Function

    Public Function MoveFile(ByVal PathOld As String, ByVal PathNew As String, ByVal Notify As Boolean) As Boolean Implements ifzFilesManager.MoveFile

    End Function

    Public Function RenameDirectory(ByVal PathOld As String, ByVal PathNew As String, ByVal Notify As Boolean) As Boolean Implements ifzFilesManager.RenameDirectory
        If IO.Directory.Exists(PathNew) Then
            MsgBox(Object_Language.Lang_Text("Directory exists"), MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Rename"))
            Return False
        Else
            IO.Directory.Move(PathOld, PathNew)
            Return True
        End If
    End Function

    Public Function RenameFile(ByVal PathOld As String, ByVal PathNew As String, ByVal Notify As Boolean) As Boolean Implements ifzFilesManager.RenameFile
        If IO.File.Exists(PathNew) Then
            MsgBox(Object_Language.Lang_Text("File exists"), MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Rename"))
            Return False
        Else
            IO.Directory.Move(PathOld, PathNew)
            Return True
        End If
    End Function

    Public Function SetContentFile(ByVal Path As String, ByVal Content As String) As Boolean Implements ifzFilesManager.SetContentFile
        Try
            If IO.File.Exists(Path) Then
                Dim sw As StreamWriter = New StreamWriter(Path)
                sw.Write(Content)
                sw.Flush()
                sw.Close()
                Return True
            Else
                MsgBox(Object_Language.Lang_Text("File not exists") & " [" & Path & "]", MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Creating new file"))
                Return False
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, Object_Language.Lang_Text("Creating new file"))
        End Try
    End Function
End Class
